<!-- <!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <style type="text/css">
      body,html,#container{
        width: 100%;
        height: 100%;
        margin: 0px
      }
    </style>
    <title>API加载</title>
  </head>
  <body>
    <div id="container" tabindex="0"></div>
    <script src="https://webapi.amap.com/maps?v=1.4.14&key=c1ca4f3174d3f09fa32889f6d5a03733"></script>
    <script type="text/javascript">
        var map = new AMap.Map('container', {
           resizeEnable: true,
           center:[116.480983, 39.989628],
           zoom:11
        });
        AMap.plugin('AMap.ToolBar',function(){
           var toolbar = new AMap.ToolBar();
           map.addControl(toolbar)
        })

        var m1 = new AMap.Marker({
            position: [116.49, 39.9]
        });
        var m2 = new AMap.Marker({
            position: [116.29, 39.9]
        });
        var m3 = new AMap.Marker({
            position: [116.69, 39.9],
            icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png"
        });

        map.add(m1);
        map.add(m2);
        map.add(m3);

        m1.on('click', clickOff);
        function clickOff(){
            alert('@');
        }

        // map.setFitView([m1, m2, m3]);

        map.setFitView();

        AMap.plugin('AMap.Geolocation', function() {
            var geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                timeout: 10000,          //超过10秒后停止定位，默认：5s
                buttonPosition:'RB',    //定位按钮的停靠位置
                buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                zoomToAccuracy: true,   //定位成功后是否自动调整地图视野到定位点

            });
            map.addControl(geolocation);
            geolocation.getCurrentPosition(function(status,result){
                if(status=='complete'){
                    onComplete(result)
                }else{
                    onError(result)
                }
            });
        });
        //解析定位结果
        function onComplete(data) {
            document.getElementById('status').innerHTML='定位成功'
            var str = [];
            str.push('定位结果：' + data.position);
            str.push('定位类别：' + data.location_type);
            if(data.accuracy){
                str.push('精度：' + data.accuracy + ' 米');
            }//如为IP精确定位结果则没有精度信息
            str.push('是否经过偏移：' + (data.isConverted ? '是' : '否'));
            document.getElementById('result').innerHTML = str.join('<br>');
        }
        //解析定位错误信息
        function onError(data) {
            document.getElementById('status').innerHTML='定位失败'
            document.getElementById('result').innerHTML = '失败原因排查信息:'+data.message;
        }
    </script>
    <script type="text/javascript" src="https://webapi.amap.com/demos/js/liteToolbar.js"></script>
  </body>
</html> -->
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=EA9FQlF2XFisdEGEU5BwWtXtDoLDLPQq"></script>
	<title>浏览器定位</title>
</head>
<body>
	<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
    window.document.addEventListener('message', function(msg) {
        var mpoint= JSON.parse(msg.data);
        setPoint(JSON.parse(msg.data));
    });

	// 百度地图API功能
    var map = new BMap.Map("allmap");
    map.addControl(new BMap.MapTypeControl({
		mapTypes:[
            BMAP_NORMAL_MAP,
            BMAP_HYBRID_MAP
        ]}));
	var point = new BMap.Point(116.404, 39.915);
	map.centerAndZoom(point,12);

    translateCallback = (data) => {
      if(data.status === 0) {

        var marker = new BMap.Marker(data.points[0]);
        map.addOverlay(marker);
       //  map.setCenter(data.points[0]);
        map.centerAndZoom(data.points[0],12);
      }
    }

    setPoint = function (data){
        var point = new BMap.Point(data.lng,data.lat);
        // var point = new BMap.Point(112.944409,28.128927);
        var pointArr = [];
        pointArr.push(point);
        var convertor = new BMap.Convertor();
        convertor.translate(pointArr, 1, 5, translateCallback);
    }

    // setTimeout(function(){
    //     var convertor = new BMap.Convertor();
    //     var pointArr = [];
    //     pointArr.push(ggPoint);
    //     convertor.translate(pointArr, 1, 5, translateCallback)
    // }, 1000);

    // var geolocation = new BMap.Geolocation();
	// geolocation.getCurrentPosition(function(r){
	// 	if(this.getStatus() == BMAP_STATUS_SUCCESS){
	// 		var mk = new BMap.Marker(r.point);
	// 		// map.addOverlay(mk);
	// 		// map.panTo(r.point);
    //         // alert('您的位置：'+r.point.lng+  112.944409','+r.point.lat 28.128927);
    //         // var convertor = new BMap.Convertor();
    //         // var ggPoint = r.point;
    //         // var ggPoint = new BMap.Point(112.944409,28.128927);
    //         var ggPoint = new BMap.Point(r.point.lng,r.point.lat);
    //         a+= ggPoint.lng +"@" +ggPoint.lat;
    //         var pointArr = [];
    //         pointArr.push(ggPoint);
    //         // alert(JSON.stringify(ggPoint));
    //         convertor.translate(pointArr, 1, 5, translateCallback)
	// 	}
	// 	else {
	// 		alert('failed'+this.getStatus());
	// 	}
    // },{enableHighAccuracy: true})

	//关于状态码
	//BMAP_STATUS_SUCCESS	检索成功。对应数值“0”。
	//BMAP_STATUS_CITY_LIST	城市列表。对应数值“1”。
	//BMAP_STATUS_UNKNOWN_LOCATION	位置结果未知。对应数值“2”。
	//BMAP_STATUS_UNKNOWN_ROUTE	导航结果未知。对应数值“3”。
	//BMAP_STATUS_INVALID_KEY	非法密钥。对应数值“4”。
	//BMAP_STATUS_INVALID_REQUEST	非法请求。对应数值“5”。
	//BMAP_STATUS_PERMISSION_DENIED	没有权限。对应数值“6”。(自 1.1 新增)
	//BMAP_STATUS_SERVICE_UNAVAILABLE	服务不可用。对应数值“7”。(自 1.1 新增)
	//BMAP_STATUS_TIMEOUT	超时。对应数值“8”。(自 1.1 新增)
</script>
